﻿/// <reference path="jquery-1.5.1-vsdoc.js" />
/// <reference path="jquery-ui-1.8.11.js" />

$(document).ready(function () {

    $(":input[data-autocomplete]").each(function () {
        $(this).autocomplete({
            source: $(this).attr("data-autocomplete"),
            select: function (event, ui) {
                var loc = $(this).attr("data-href").toString() + "/" + ui.item.id;
                $(window.location).attr('href', loc);
            }
        })
    });
})

$(document).ready(function () {
    //$.datepicker.setDefaults($.datepicker.regional['ru']);
    $(":input[data-datepicker]").datepicker();
    //$(":input[data-datepicker]").datepicker($.datepicker.regional['ru']);

    //var lang = $('html').attr("lang");
    var l_lang;
    if (navigator.userLanguage) // Explorer
        l_lang = navigator.userLanguage;
    else if (navigator.language) // FF
        l_lang = navigator.language;
    else
        l_lang = "en";

    $.datepicker.setDefaults($.datepicker.regional[l_lang]);
})

/////to complete
$(document).ready(function () {
    var sum = 0;
    $('.UnitPrice').each(function () {
        sum += Number(jQuery.trim($(this).text()));
    });
    $('.TotalUnitPrice').val("dfdf");
})

$(document).ready(function () {
    $('label.hint').each(function () {
        var label = $(this);
        var input = $('#' + label.attr('for'));
        var initial = label.hide().text().replace(':', '');
        input.focus(function () {
            //input.css('backgroundColor', '#F0F0F0');
            if (input.val() == initial) {
                input.val('');
            }
        }).blur(function () {
            //input.css('backgroundColor', '#FFFFFF');
            if (input.val() == '') {
                input.val(initial);
            }
        }).val(initial);
    });
});

$(document).ready(function () {
    if ($.validator == null)
        return;
    $.validator.methods.range = function (value, element, param) {
        var globalizedValue = value.replace(",", ".");
        return this.optional(element) || (globalizedValue >= param[0] && globalizedValue <= param[1]);
    }

    $.validator.methods.number = function (value, element) {
        return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:[\s\.,]\d{3})+)(?:[\.,]\d+)?$/.test(value);
    }

    /*jQuery.extend(jQuery.validator.methods, {
    number: function (value, element) {
    return this.optional(element) ||
    /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
    }
    });*/
});